/**
 * @param {number} n
 * @return {number}
 */
var pivotInteger = function (n) {
  let m = n*(n+1)/2, x= Math.floor(Math.sqrt(m))
  return x*x == m?x:-1
};

pivotInteger(3)